//
//  LogInView.swift
//  ShiZhe
//
//  Created by 陈卿伟 on 16/8/29.
//  Copyright © 2016年 陈卿伟. All rights reserved.
//

import UIKit

class LogInView: UIView {
    
    var registerButton:UIButton!//注册按钮
    var visitorButton:UIButton!//游客模式
    
    override init(frame: CGRect) {
        registerButton = UIButton()
        visitorButton = UIButton()
        super.init(frame: frame)
        self.addBGImage()
        self.addLogo()
        self.addTwoLabel()
        self.addLogInWay()
        self.createRegisterAccount()
        self.createVisitorVisit()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

//MARK:--UI设置
extension LogInView{

    //添加背景图片
    func addBGImage(){
        let bgImageView = UIImageView(frame: MainBounds)
        bgImageView.image = UIImage(named: "LoginBGImage")
        self.addSubview(bgImageView)
    }
    
    //添加 logo
    func addLogo(){
        let logoImageView = UIImageView(frame: CGRect(x: 148*SCALEW, y: 94*SCALEH, width: 80*SCALEW, height: 80*SCALEH))
        logoImageView.image = UIImage(named: "APPIcon")
        self.addSubview(logoImageView)
    }
    
    //添加两段文字
    func addTwoLabel(){
        let chineseLabel = UILabel(frame: CGRect(x: 0,y: 190*SCALEH,width: WidthAPP,height: 21*SCALEH))
        chineseLabel.textAlignment = .Center
        chineseLabel.textColor = UIColor.whiteColor()
        chineseLabel.text = "－－欲戴王冠 必承其重－－"
        chineseLabel.font = BaseFunc.getLightFont(15)
        self.addSubview(chineseLabel)
        
        let englishLabel = UILabel(frame: CGRect(x: 0,y: 217*SCALEH,width: WidthAPP,height: 21*SCALEH))
        englishLabel.textAlignment = .Center
        englishLabel.textColor = UIColor.whiteColor()
        englishLabel.text = "One who wants to wear the crown, bears the crown"
        englishLabel.font = UIFont(name: "Zapfino", size: 11*SCALEW)
        self.addSubview(englishLabel)
    }
    
    //添加手机 微信 qq 微博 选择框
    func addLogInWay(){
        let image = ["phoneP","QQP","wechatP","weiboP"]
        let title = ["手机","QQ","微信","微博"]
        for i in 0..<4{
            let logButton = UIButton(frame: CGRect(x: 59*SCALEW,y: 300*SCALEH+CGFloat(i)*55*SCALEH,width: 257*SCALEW,height: 40*SCALEH))
            logButton.tag = 100860+i
            logButton.backgroundColor = UIColor.clearColor()
            logButton.layer.borderWidth = 1
            logButton.layer.borderColor = UIColor.whiteColor().CGColor
            logButton.layer.cornerRadius = 4
            logButton.setImage(UIImage(named: image[i]), forState: UIControlState())
            logButton.setTitle(title[i], forState: UIControlState())
            logButton.titleLabel?.font = BaseFunc.getCustomFont(13)
            if i == 1{
                logButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 12)
            }else{
                logButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 2)
            }
            
            if i == 0{
                logButton.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 0)
            }else{
                logButton.titleEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0)
            }
            
            self.addSubview(logButton)
        }
    }
    
    //创建注册账号
    func createRegisterAccount(){
        registerButton.frame = CGRect(x: 40*SCALEW, y: 576*SCALEH, width: 66*SCALEW, height: 19*SCALEH)
        registerButton.setTitle("注册账号", forState: UIControlState())
        registerButton.titleLabel?.font = BaseFunc.getCustomFont(16)
        registerButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState())
        self.addSubview(registerButton)
    }
    
    //创建游客游览
    func createVisitorVisit(){
        visitorButton.frame = CGRect(x: 271*SCALEW, y: 576*SCALEH, width: 66*SCALEW, height: 19*SCALEH)
        visitorButton.setTitle("游客访问", forState: UIControlState())
        visitorButton.titleLabel?.font = BaseFunc.getCustomFont(16)
        visitorButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState())
        self.addSubview(visitorButton)
    }
}







